﻿using System;

using MSAcademic.v2.Infrastructure.AccessRights;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Areas.Admin.Models.Home
{
    public partial class IndexModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;

        public bool CanView
        {
            get
            {
                if (_canView == null)
                {
                    _canView = new Lazy<bool>(() => this.SignedInUser != null);
                }
                return _canView.Value;
            }
        }
        private Lazy<bool> _canView;

        public bool CanAccessTags
        {
            get
            {
                if (_canAccessTags == null)
                {
                    _canAccessTags = new Lazy<bool>(() => this.SignedInUser != null && _accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.TagControl));
                }
                return _canAccessTags.Value;
            }
        }
        private Lazy<bool> _canAccessTags;

        public bool CanAccessSections
        {
            get
            {
                if (_canAccessSections == null)
                {
                    
                    _canAccessSections = new Lazy<bool>(() => this.SignedInUser != null && _accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.SectionControl));
                }
                return _canAccessSections.Value;
            }
        }
        private Lazy<bool> _canAccessSections;
    }

    public partial class IndexModel
    {
        private readonly ILoginService _loginService;
        private readonly IAccessRightsService _accessRightsService;

        public IndexModel(
            ILoginService loginService,
            IAccessRightsService accessRightsService)
        {
            _loginService = loginService;
            _accessRightsService = accessRightsService;
        }
    }
}